#!/bin/bash

# 便携版 lighttpd 启动脚本
BASEDIR=$(cd "$(dirname "$0")"; pwd)
echo "Lighttpd 便携版启动于: $BASEDIR"

# 如果未使用 patchelf 修改 RPATH，需要通过环境变量指定库路径
# export LD_LIBRARY_PATH="$BASEDIR/lib:$LD_LIBRARY_PATH"

# 检查配置文件语法
echo "检查配置文件语法..."
$BASEDIR/bin/lighttpd -t -f "$BASEDIR/etc/lighttpd.conf"
if [ $? -ne 0 ]; then
    echo "错误：配置文件语法检查失败！"
    echo "Error: Configuration file syntax check failed!"
    exit 1
fi

# 启动 lighttpd (前台运行，便于观察日志)
echo "---------------------------------------"
echo "启动 lighttpd 服务器..."
echo "Starting the lighttpd server..."
echo "---------------------------------------"
echo "端口：8081 | Port: 8081"
echo "Ctrl+c退出/结束 | Ctrl C to exit/end"
exec "$BASEDIR/bin/lighttpd" -D -f "$BASEDIR/etc/lighttpd.conf" -m "$BASEDIR/lib"
